package com.xidian.GMS.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xidian.GMS.dto.Page;
import com.xidian.GMS.entity.Announcement;
import com.xidian.GMS.entity.EmploymentLawsAndRegulations;
import com.xidian.GMS.mapper.EmploymentLawsAndRegulationsMapper;
import com.xidian.GMS.service.EmploymentLawsAndRegulationsService;

@Service
public class EmploymentLawsAndRegulationsServiceImpl implements EmploymentLawsAndRegulationsService {

	@Autowired
	private EmploymentLawsAndRegulationsMapper EmploymentLawsAndRegulationsMapper;
	
	
	@Override
	public EmploymentLawsAndRegulations Insert( String title, Date uploadtime,String content) {
		
	   EmploymentLawsAndRegulations EmploymentLawsAndRegulations = new EmploymentLawsAndRegulations();
	  System.out.println(title);
    	EmploymentLawsAndRegulations.setLawsName(title);;
    	EmploymentLawsAndRegulations.setLawsContent(content);
    	EmploymentLawsAndRegulations.setLawsUpdatetime(uploadtime);
   	  int rows = EmploymentLawsAndRegulationsMapper.insert(EmploymentLawsAndRegulations);
		if( EmploymentLawsAndRegulations == null ||rows == 0){
			throw new RuntimeException("错误");
		}
          return EmploymentLawsAndRegulations;
    }
	

	@Override
	public boolean delete(int EmploymentLawsAndRegulationsid) {
        int x =  EmploymentLawsAndRegulationsMapper.deleteByPrimaryKey(EmploymentLawsAndRegulationsid);
  	  if (x == 1) {
  	  	  return true;
	}
          return false;
    }	

	@Override
	public boolean update(int EmploymentLawsAndRegulationsid, String title, String content,Date edittime) {
		   EmploymentLawsAndRegulations EmploymentLawsAndRegulations2 = EmploymentLawsAndRegulationsMapper.selectByPrimaryKey(EmploymentLawsAndRegulationsid);
			
		   EmploymentLawsAndRegulations2.setLawsName(title);;
	    	EmploymentLawsAndRegulations2.setLawsContent(content);
	    	EmploymentLawsAndRegulations2.setLawsUpdatetime(edittime);
	   	 
		
           int temp = EmploymentLawsAndRegulationsMapper.updateByPrimaryKeySelective(EmploymentLawsAndRegulations2);
		
       	  if (temp == 1) {
      	  	  return true;
    	}
              return false;
        }
	
	@Override
	public Page getEmploymentLawsAndRegulations(int cur) {
		Page page = new Page(cur);
		
		int count = EmploymentLawsAndRegulationsMapper.count();
		
		List<EmploymentLawsAndRegulations> lawlist = EmploymentLawsAndRegulationsMapper.findAll(page.getOffset(), page.getSize());
		
		page.setCount(count);
		page.setList(lawlist);
		
		return page;
	}
}


